package com.sdry.web.controller.llm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.sdry.model.hpf.Page;
import com.sdry.model.llm.ExceptionLog;
import com.sdry.service.llm.ExceptionLogService;
import com.sdry.utils.ResponseUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

/** 
* 异常日志
* @author lian 
* @version 1.0
* @time 2018年10月17日 上午12:47:07
*/

@Controller
@RequestMapping("/exceptionLogMana")
public class ExceptionLogController {
	
	@Resource
	private ExceptionLogService exLogService;
	
	/**
	 * 分页查询异常日志信息
	 * @param page 分页条件
	 * @param exceptionLog 异常日志
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping(value="/listPageExceptionLog")
	public void listPageExceptionLog(Page page, ExceptionLog exceptionLog, HttpServletResponse response) throws Exception{
		Map<String, Object> map = new HashMap<>();
		map.put("limit", page.getLimit());
		map.put("page", page.getPage());
		if (exceptionLog.getExceptionMsg() != null ) {
			map.put("exceptionMsg", exceptionLog.getExceptionMsg());
		} else {
			map.put("exceptionMsg", "");
			exceptionLog.setExceptionMsg("");
		}
		int count = exLogService.countExceptionLog(exceptionLog);
		List<ExceptionLog> ecLogList = exLogService.listPageExceptionLog(map);
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		JSONArray jsonArray = JSONArray.fromObject(ecLogList, jsonConfig);
		jsonObject.put("code", 0);
		jsonObject.put("data", jsonArray);
		jsonObject.put("count", count);
		ResponseUtil.write(response, jsonObject);
			
	}
	
	/**
	 * 删除异常日志
	 * @param str 异常id组成的字符串
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping(value="/deleteExceptionLog")
	public void deleteExceptionLog(@RequestParam("str") String str, HttpServletResponse response) throws Exception{
		int isSuccess = exLogService.deleteExceptionLog(str);
		ResponseUtil.write(response, isSuccess);
	}

}
